package com.lazycat.backend.service.impl.address;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lazycat.backend.mapper.AddressMapper;
import com.lazycat.backend.mapper.UserAddressMapper;
import com.lazycat.backend.pojo.Address;
import com.lazycat.backend.pojo.UserAddress;
import com.lazycat.backend.service.address.DelAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class DelAddressServiceImpl implements DelAddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public Map<String, Object> del(Integer addressId) {
        QueryWrapper<Address> addressQueryWrapper = new QueryWrapper<>();
        QueryWrapper<UserAddress> userAddressQueryWrapper = new QueryWrapper<>();
        addressQueryWrapper.eq("address_id", addressId);
        addressMapper.delete(addressQueryWrapper);
        userAddressQueryWrapper.eq("address_id", addressId);
        userAddressMapper.delete(userAddressQueryWrapper);
        HashMap<String, Object> resp = new HashMap<>();
        resp.put("error_message", "success");
        return resp;
    }
}
